package com.zhuss.team.processor;

import com.zhuss.bean.bo.team.invest.SearchInvestBo;
import com.zhuss.bean.vo.team.invest.DetailInvestVo;
import com.zhuss.bean.vo.team.invest.ListInvestVo;
import com.zhuss.common.PageVo;
import com.zhuss.core.processor.EnumConfig;
import com.zhuss.exception.WpsException;
import com.zhuss.exception.ExceptionCode;
import com.zhuss.team.db.dao.ext.InvestDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: zhushanshuo
 * @Date: 2020/3/26 13:25
 */
@Component("investRead")
public class InvestRead {

    @Autowired
    private InvestDao investDao;

    @Autowired
    private EnumConfig enumConfig;

    /**
     * 列表
     * @param bo
     */
    public Object list(SearchInvestBo bo) {
        PageVo<ListInvestVo> result = new PageVo<ListInvestVo>();
        result.setPageNum(bo.getPageNum());
        result.setPageSize(bo.getPageSize());
        result.setItems(investDao.list(bo));
        for (ListInvestVo item : result.getItems()){
            item.setInvestGroupName(enumConfig.investGroupName(item.getInvestGroup(),item.getArea()));
        }
        result.setTotal(investDao.countList(bo));
        return result;
    }

    /**
     * 详情
     * @param investId
     * @throws WpsException
     */
    public Object detail(Long investId) throws WpsException {
        Object result = investDao.detail(investId);

        if (result == null) {
            throw new WpsException(ExceptionCode.数据不存在);
        }
        ((DetailInvestVo)result).setInvestGroupName(enumConfig.investGroupName( ((DetailInvestVo)result).getInvestGroup(), ((DetailInvestVo)result).getArea()));
        return result;
    }

    /**
     * 获取问卷下拉框
     * @param area
     * @return
     * @throws WpsException
     */
    public Object getInvestList(Integer area) throws WpsException {
        Object result = investDao.getInvestList(area);
        return result;
    }
}
